package org.strangewt.demo.composit;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.strangewt.widgets.CompositeBase;

public class CompositeBaseShowcase extends CompositeBase implements SelectionListener {

	public CompositeBaseShowcase(Composite parent, int style) {
		super(parent, style);
		
		setLayout(new GridLayout());
		createLabel(this, getClass().getName());
		
		createControlByWindowBuilder(this);
		createControlByHand(this);
		createControlConvenient(this);
		createControlByDemoWidgetHelper(this);
	}

	

	private void createControlByWindowBuilder(Composite parent) {
		Group group2 = new Group(this, SWT.NONE);
		group2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		group2.setText("by window builder");
		group2.setLayout(new GridLayout(2, false));
		
		Label label0 = new Label(group2, SWT.NONE);
		label0.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label0.setText("label0");
		
		Text text0 = new Text(group2, SWT.BORDER);
		text0.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label1 = new Label(group2, SWT.NONE);
		label1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label1.setText("label1");
		
		Text text1 = new Text(group2, SWT.BORDER | SWT.V_SCROLL);
		GridData gd_text1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_text1.heightHint = 50;
		text1.setLayoutData(gd_text1);
		
		Label label2 = new Label(group2, SWT.NONE);
		label2.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label2.setText("label2");
		
		Text text2 = new Text(group2, SWT.BORDER | SWT.V_SCROLL);
		GridData gd_text2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 2);
		gd_text2.heightHint = 50;
		text2.setLayoutData(gd_text2);
		
		Label label3 = new Label(group2, SWT.NONE);
		label3.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
		label3.setText("label3");
		
		Composite composite = new Composite(group2, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
		
		Button btOk = new Button(composite, SWT.NONE);
		btOk.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		btOk.setText("OK");
		btOk.addSelectionListener(this);
		
		Button btCancel = new Button(composite, SWT.NONE);
		btCancel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		btCancel.setText("CANCEL");
		btCancel.addSelectionListener(this);
	}
	
	private void createControlByHand(Composite parent) {
		
		Group group0 = new Group(parent, SWT.NONE);
		group0.setText("by hand");
		group0.setLayout( new GridLayout(2, false));
		group0.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		
		Label label0 = new Label(group0, SWT.NONE);
		label0.setText("label0");
		
		Text text0 = new Text(group0, SWT.BORDER);
		text0.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		
		Label label1 = new Label(group0, SWT.NONE);
		label1.setText("label1");
		label1.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		
		Text text1 = new Text(group0, SWT.V_SCROLL | SWT.MULTI | SWT.WRAP | SWT.BORDER);
		GridData gd1 =  new GridData(SWT.FILL, SWT.CENTER, true, false);
		gd1.heightHint = 50;
		text1.setLayoutData(gd1);
		
		Label label2 = new Label(group0, SWT.NONE);
		label2.setText("label2");
		label2.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		
		Text text2 = new Text(group0, SWT.V_SCROLL | SWT.MULTI | SWT.WRAP | SWT.BORDER);
		GridData gd2 =  new GridData(SWT.FILL, SWT.CENTER, true, false);
		gd2.heightHint = 50;
		gd2.verticalSpan = 2;
		text2.setLayoutData(gd2);
		
		Label label3 = new Label(group0, SWT.NONE);
		label3.setText("label3");
		label3.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		
		Composite composite = new Composite(group0, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
		
		Button btOk = new Button(composite, SWT.PUSH);
		btOk.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		btOk.setText("OK");
		btOk.addSelectionListener(this);
		
		Button btCancel = new Button(composite, SWT.PUSH);
		btCancel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		btCancel.setText("CANCEL");
		btCancel.addSelectionListener(this);
	}
	
	private void createControlConvenient(Composite parent) {
		
		Group group1 = createGroup(parent, "by convenient", 2);
		
		createLabel(group1, "label0");
		createText(group1);
		
		createLabelTop(group1, "label1");
		createTextField(group1, 0, 50);
		
		createLabelTop(group1, "label2");
		createTextField(group1, 0, 50, 1, 2);
		createLabelTop(group1, "label3");
		
		Composite composite = createComposite(group1, 2);
		composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
		createButton(composite, "OK", this);
		createButton(composite, "CANCEL", this);
	}
	
	private void createControlByDemoWidgetHelper(Composite parent) {
		
		GroupDemoWidgetHelper group = new GroupDemoWidgetHelper(parent, SWT.NONE);
		group.setText("by DemoWidgetHelper");
		group.setLayoutData(createGridDataForInputFields());
	}

	// SelectionListener /////////////////////////////////////////////
	
	@Override
	public void widgetSelected(SelectionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
		// TODO Auto-generated method stub
		
	}
}
